/*
 * Copyright (c) 2021-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.ffmpeg.ohos.sample.slice;

import ohos.agp.components.Button;
import ohos.agp.components.Text;
import org.ffmpeg.ohos.sample.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import org.ffmpeg.ohos.sample.tests.DemoCrossFadeCatTest;
import org.ffmpeg.ohos.sample.tests.DemoDrawBoxVideoFilter;
import org.ffmpeg.ohos.sample.tests.DemoSoxTrimAudio;
import org.ffmpeg.ohos.sample.tests.DemoTransposeVideoFilter;
import org.ffmpeg.ohos.sample.tests.DemoTrim;

public class MainAbilitySlice extends AbilitySlice {
    Button mbtnTestCase1;
    Text mtcTestCase1;
    Text mtcTestCaseStatus1;
    Button mbtnTestCase2;
    Text mtcTestCase2;
    Text mtcTestCaseStatus2;
    Button mbtnTestCase3;
    Text mtcTestCase3;
    Text mtcTestCaseStatus3;
    Button mbtnTestCase4;
    Text mtcTestCase4;
    Text mtcTestCaseStatus4;
    Button mbtnTestCase5;
    Text mtcTestCase5;
    Text mtcTestCaseStatus5;
    
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        mbtnTestCase1 = (Button) findComponentById(ResourceTable.Id_btnTestCase1);
        mtcTestCase1 = (Text) findComponentById(ResourceTable.Id_tcTestCase1);
        mtcTestCaseStatus1 = (Text) findComponentById(ResourceTable.Id_tcTestCaseStatus1);
        mbtnTestCase2 = (Button) findComponentById(ResourceTable.Id_btnTestCase2);
        mtcTestCase2 = (Text) findComponentById(ResourceTable.Id_tcTestCase2);
        mtcTestCaseStatus2 = (Text) findComponentById(ResourceTable.Id_tcTestCaseStatus2);
        mbtnTestCase3 = (Button) findComponentById(ResourceTable.Id_btnTestCase3);
        mtcTestCase3 = (Text) findComponentById(ResourceTable.Id_tcTestCase3);
        mtcTestCaseStatus3 = (Text) findComponentById(ResourceTable.Id_tcTestCaseStatus3);
        mbtnTestCase4 = (Button) findComponentById(ResourceTable.Id_btnTestCase4);
        mtcTestCase4 = (Text) findComponentById(ResourceTable.Id_tcTestCase4);
        mtcTestCaseStatus4 = (Text) findComponentById(ResourceTable.Id_tcTestCaseStatus4);
        mbtnTestCase5 = (Button) findComponentById(ResourceTable.Id_btnTestCase5);
        mtcTestCase5 = (Text) findComponentById(ResourceTable.Id_tcTestCase5);
        mtcTestCaseStatus5 = (Text) findComponentById(ResourceTable.Id_tcTestCaseStatus5);
        initComponents();
    }

    private void initComponents() {
        mbtnTestCase1.setClickedListener(component -> {
            mtcTestCaseStatus1.setText("Status: Started");
            if (DemoTrim.execute(getContext())) {
                mtcTestCaseStatus1.setText("Status: Completed");
            } else{
                mtcTestCaseStatus1.setText("Status: Failed");
            }
        });
        mbtnTestCase2.setClickedListener(component -> {
            mtcTestCaseStatus2.setText("Status: Started");
            if (DemoTransposeVideoFilter.execute(getContext())) {
                mtcTestCaseStatus2.setText("Status: Completed");
            } else{
                mtcTestCaseStatus2.setText("Status: Failed");
            }
        });
        mbtnTestCase3.setClickedListener(component -> {
            mtcTestCaseStatus3.setText("Status: Started");
            if (DemoDrawBoxVideoFilter.execute(getContext())) {
                mtcTestCaseStatus3.setText("Status: Completed");
            } else{
                mtcTestCaseStatus3.setText("Status: Failed");
            }
        });
        mbtnTestCase4.setClickedListener(component -> {
            mtcTestCaseStatus4.setText("Status: Started");
            if (DemoSoxTrimAudio.execute(getContext())) {
                mtcTestCaseStatus4.setText("Status: Completed");
            } else{
                mtcTestCaseStatus4.setText("Status: Failed");
            }
        });
        mbtnTestCase5.setClickedListener(component -> {
            mtcTestCaseStatus5.setText("Status: Started");
            if (DemoCrossFadeCatTest.execute(getContext())) {
                mtcTestCaseStatus5.setText("Status: Completed");
            } else{
                mtcTestCaseStatus5.setText("Status: Failed");
            }
        });
    }
}
